//
//  JYTCoachViewController.m
//  JYT_IOS
//
//  Created by nxa-tankeke on 17/1/13.
//  Copyright © 2017年 nxa-yuanguoxiang. All rights reserved.
//

#import "JYTCoachViewController.h"
#import "JYTSearchCoachViewController.h"
#import "JYTCity.h"
#import "JYTZone.h"
#import "JYTCityZoneView.h"
#import "JYTPopupMenu.h"
#import "JYTPopsexMenu.h"

#define TITLES @[@"星级", @"先学后付", @"价格", @"人气",@"接送"]
#define ICONS  @[@"motify",@"motify",@"motify",@"motify",@"motify"]

#define SEXTITLES @[@"女", @"男"]
#define SEXICONS  @[@"03驾校详细信息_20",@"03驾校详细信息_17"]

@interface JYTCoachViewController ()<JYTPopupMenuDelegate, JYTPopsexMenuDelegate>
@property (nonatomic, strong)NSMutableArray * coaches;

@property (nonatomic, strong)JYTCity *currentCity;
@property (nonatomic, strong)JYTZone *currentZone;
@property (nonatomic, strong)UIButton *btn;
@property (nonatomic, strong)UIButton *slectBtn;
@property (nonatomic, strong)UIButton *sexBtn;

@property (nonatomic, copy)NSString *currentFilter;
@property (nonatomic, copy)NSString *currentSex;
@end

@implementation JYTCoachViewController

-(NSMutableArray *)coaches
{
    if (_coaches == nil) {
        _coaches = [NSMutableArray array];
    }
    
    return _coaches;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSDictionary *dic = @{@"lftBtnBgImg":@"ic_goback",
                          @"lftBtnTitle":@"no",
                          @"pageTitle":@"找教练",
                          @"rhtBtnBgImg":@"ic_goback",
                          @"rhtBtnTitle":@"no"};
    [self setNavgationBarWithDic:dic];
    

    BOOL isUsedOffLine = [[JYTUserManager shared] isUsedOffLine];
    if (!isUsedOffLine) {
        
        User *user = [[JYTUserManager shared] getUser];
        _currentCity = [[JYTUserManager shared] getCityById:user.cityId];
        
    }else {
        _currentCity =[[[JYTUserManager shared] getCityArr] firstObject];
        
    }
    
    JYTZone * first = [[JYTZone alloc]init];
    first.zone_id = _currentCity.zone_id;
    first.zone_name = _currentCity.zone_name;
    first.parent_id = _currentCity.parent_id;
    first.service_url = _currentCity.service_url;
    first.weixin_url = _currentCity.weixin_url;
    _currentZone = first;
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:self action:@selector(slectZone) forControlEvents: UIControlEventTouchUpInside];
    btn.backgroundColor = [UIColor whiteColor];
    btn.frame = CGRectMake(0, 64, CURRENT_SCREEN_WIDTH / 3, 46);
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
    [btn setTitle:_currentCity.zone_name forState:UIControlStateNormal];
    [btn.layer setBorderWidth:1.0];
    self.btn = btn;
    [self.view addSubview:btn];
    
    UIButton *slectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    slectBtn.backgroundColor = [UIColor whiteColor];
    slectBtn.frame = CGRectMake(CURRENT_SCREEN_WIDTH / 3, 64, CURRENT_SCREEN_WIDTH / 3, 46);
    [slectBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [slectBtn.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
    [slectBtn setTitle:@"星级" forState:UIControlStateNormal];
    [slectBtn.layer setBorderWidth:1.0];
    _currentFilter = @"0";
    [slectBtn addTarget:self action:@selector(slectFilter:) forControlEvents:UIControlEventTouchUpInside];
    self.slectBtn = slectBtn;
    [self.view addSubview:slectBtn];
    
    UIButton *sexBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sexBtn.backgroundColor = [UIColor whiteColor];
    sexBtn.frame = CGRectMake((CURRENT_SCREEN_WIDTH / 3)* 2, 64, CURRENT_SCREEN_WIDTH / 3, 46);
    [sexBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [sexBtn.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
    [sexBtn setTitle:@"全部性别" forState:UIControlStateNormal];
    [sexBtn.layer setBorderWidth:1.0];
    _currentSex = @"";
    [sexBtn addTarget:self action:@selector(slectSex:) forControlEvents:UIControlEventTouchUpInside];
    self.sexBtn = sexBtn;
    [self.view addSubview:sexBtn];
}

- (void)slectZone
{
    
    JYTCityZoneView *cz = [[JYTCityZoneView alloc]initWithFrame:CGRectMake(0, 64, CURRENT_SCREEN_WIDTH, 300)];
    [cz setSelect:^(NSInteger index, JYTZone *zone) {
        //MyLog(@"---------%@",zone.zone_name);
        _currentZone = zone;
        [self.btn setTitle:zone.zone_name forState:UIControlStateNormal];
        
        //[self.schoolList.mj_header beginRefreshing];
        //[self.schools removeAllObjects];
        //[self.schoolList reloadData];
        //[self loadNewSchools];
    }];
    [cz show];
}


- (void)slectFilter:(UIButton *)sender
{
    [JYTPopupMenu showRelyOnView:sender titles:TITLES icons:ICONS menuWidth:150 delegate:self];
    
}

- (void)popupMenuDidSelectedAtIndex:(NSInteger)index popupMenu:(JYTPopupMenu *)popupMenu
{
    [self.slectBtn setTitle:TITLES[index] forState:UIControlStateNormal];
    _currentFilter = [NSString stringWithFormat:@"%zd", index];
    MyLog(@"===%@", _currentFilter);
    //[self.schoolList.mj_header beginRefreshing];
   // [self.schools removeAllObjects];
   // [self.schoolList reloadData];
    //[self loadNewSchools];
}


- (void)slectSex:(UIButton *)sender
{
    [JYTPopsexMenu showRelyOnView:sender titles:SEXTITLES icons:SEXICONS menuWidth:150 delegate:self];
    
}
- (void)popsexMenuDidSelectedAtIndex:(NSInteger)index popupMenu:(JYTPopsexMenu *)popupMenu
{
    [self.sexBtn setTitle:SEXTITLES[index] forState:UIControlStateNormal];
    _currentSex = [NSString stringWithFormat:@"%zd", index];
    MyLog(@"*********%@", _currentSex);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) baseGoToNextViewController
{
    JYTSearchCoachViewController *sear = [[JYTSearchCoachViewController alloc]init];
    [self pushViewController:sear];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
